package com.example.ecommercealibabanacosclient.service;


import com.example.ecommercecommon.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NacosClientService {


    private final DiscoveryClient discoveryClient;

    public NacosClientService(DiscoveryClient discoveryClient) {
        this.discoveryClient = discoveryClient;
    }

    public CommonResponse<List> getNacosClientsInfo(String serviceId) {
        log.info("get nacos client info: [{}]",serviceId);
        CommonResponse<List> response = new CommonResponse();
        response.setData(discoveryClient.getInstances(serviceId));
        return response;
    }
}